package cn.susu.test.controller;

import cn.susu.test.dao.BookDao;
import cn.susu.test.entity.Book;
import cn.susu.test.service.BookService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class BookController {

    @Autowired
    private BookService bookService;

    @GetMapping("/getBooks")
    public String getList(@RequestParam(defaultValue = "1") Integer pageNum,Model model){
        PageInfo<Book> pageInfo =  bookService.getList(pageNum);

        model.addAttribute("page",pageInfo);

        return "bookPage";
    }
    @PostMapping("del")
    public String del(Integer[] ids){
        if (ids.length>0){
            bookService.del(ids);
        }
        return "redirect:/bookPage";
    }
}
